#!/bin/ksh
####################################
# KillJavaApp.sh
# author: huguodong
####################################

APP_CLASS="com.XXX.OfflineApp"
LOG_FILE="OfflineApp.log"

DATETIME=`date`
echo "Batch Job Start on $DATETIME" > $LOG_FILE

echo "Class about to Stop is : $APP_CLASS"
echo "Class about to Stop is : $APP_CLASS">> $LOG_FILE

# get program running details, including pid
javaps=`ps -ef|grep $APP_CLASS|grep /bin/java`

#default pid
APPID=0

if [ -n "$javaps" ]
then
	echo "App detail: $javaps"
	echo "App detail: $javaps" >> $LOG_FILE
else
	APPID=0
fi

echo "App's pid is : $APPID."
echo "App's pid is : $APPID." >> $LOG_FILE

if  [[ $APPID -ne 0 ]]
then
	echo "Stopping App(PID=$APPID)..."
	echo "Stopping App(PID=$APPID)..." >> $LOG_FILE

	kill -9 $APPID
	if  [[ $? -eq 0 ]]
	then
		echo "Stop Success."
		echo "Stop Success." >> $LOG_FILE
	else
		echo "Stop Failed."
		echo "Stop Failed." >> $LOG_FILE
	fi
else
	echo "App is not Running!"
	echo "App is not Running!" >> $LOG_FILE
fi

